from Php import PhpClass
import os

class Controller(PhpClass):
	def __init__(self, name, root = '', model = True):
		PhpClass.__init__(self, name + 'Controller', 'AppController')
		self.name = name
		self.views = []
		if model:
			self.model = Model(name)
	
	def components(self, comp_list):
		self.array('components', comp_list)
	
	def helpers(self, help_list):
		self.array('helpers', help_list)
		
	def filters(self):
		self.function('beforeFilter')
		self.function('afterFilter')
		
	def addView(self, name, params = []):
		self.function(name, params)
		self.views.append(name)
	
	def outputToFile(self):
		os.chdir(self.root + 'controllers')
		self.filename = self.name.lower() + '_controller.php'
		PhpClass.outputToFile(self)
	
class Model(PhpClass):
	def __init__(self, name):
		PhpClass.__init__(self, name, 'AppModel')
		self.variable('name', name)
		self.name = name
		
	def outputToFile(self):
		os.chdir(self.root + 'models')
		self.filename = self.name.lower() + '.php'
		PhpClass.outputToFile(self)
	
class View(PhpClass):
	def __init__(self, name):
		# this one isn't a PhpClass.  It's a Php/Html File :-/
		PhpClass.__init__(self, name, 'View')
		self.name = name
		self.contents = ''
		
	def outputToFile(self, controller_name):
		os.chdir(self.root + 'views')
		if not os.path.isdir(controller_name.lower()):
			os.mkdir(controller_name.lower())
		os.chdir(controller_name.lower())
		self.filename = self.name + '.ctp'
		PhpClass.outputToFile(self, False)
	
class Component(PhpClass):
	def __init__(self, name):
		PhpClass.__init__(self, name)
	
class Helper(PhpClass):
	pass
